Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACP-77: Current validators API for SoV #3404

Open
wants to merge 256 commits into
base: master
Choose a base branch
from

Conversation

ceyonur
Copy link
Contributor

@ceyonur ceyonur commented Sep 19, 2024

This pull request introduces a new gRPC method GetCurrentValidatorSet to the ValidatorState service, allowing clients to retrieve the current validator set for a given subnet. The changes span multiple files to implement this new functionality, including updates to the protobuf definitions, client and server interfaces, and associated tests.

Additions to ValidatorState Service:

Client and Server Implementation:

State Interface and Mock Updates:

Platform VM State Changes:

ceyonur and others added 30 commits July 27, 2024 00:02
Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org>
Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com>
Signed-off-by: Ceyhun Onur <ceyhun.onur@avalabs.org>
Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org>
Signed-off-by: Ceyhun Onur <ceyhunonur54@gmail.com>
@ceyonur ceyonur changed the title Test only current validators api ACP-77: Current validators API for SoV Nov 1, 2024
@ceyonur ceyonur marked this pull request as ready for review November 1, 2024 13:59
@ceyonur ceyonur self-assigned this Nov 1, 2024
@ceyonur ceyonur added DO NOT MERGE This PR must not be merged in its current state and removed DO NOT MERGE This PR must not be merged in its current state labels Nov 4, 2024
Base automatically changed from implement-acp-77-sov-validators-state to master November 5, 2024 16:39
@ceyonur ceyonur removed the DO NOT MERGE This PR must not be merged in its current state label Nov 5, 2024
vms/platformvm/state/state_test.go Outdated Show resolved Hide resolved
vms/platformvm/state/state_test.go Show resolved Hide resolved
vms/platformvm/state/state_test.go Show resolved Hide resolved
vms/platformvm/state/state_test.go Show resolved Hide resolved
ctx context.Context,
subnetID ids.ID,
) (map[ids.ID]*GetCurrentValidatorOutput, uint64, bool, error) {
ctx, span := s.tracer.Start(ctx, s.getValidatorSetTag, oteltrace.WithAttributes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we fix this in this PR? Seems simple enough to do so.

Copy link
Contributor

@iansuvak iansuvak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the minor question on the protobuf

message Validator {
bytes node_id = 1;
uint64 weight = 2;
bytes public_key = 3;
}

message CurrentValidator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly dumb question but is there a good reason for not adding new fields to the existing Validator message instead of adding a new one? i.e. do we see the data returned by them becoming incompatible at some point? It seems like it should be compatible since protobuf fields are all optional

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would mean a breaking change. Changing Validator would require changes to related functions + clients. I think if we want to we can deprecate old methods and types in favor of CurrentValidator. @StephenButtolph

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just have a field of type Validator in CurrentValidator? then you don't need to copy the first three fields.

@darioush
Copy link
Contributor

darioush commented Nov 6, 2024

My main question with this also in conjunction with ava-labs/subnet-evm#1263, is whether there is a possibility that the SoV validator would share the same nodeID as the ones initially set?

@ceyonur
Copy link
Contributor Author

ceyonur commented Nov 6, 2024

My main question with this also in conjunction with ava-labs/subnet-evm#1263, is whether there is a possibility that the SoV validator would share the same nodeID as the ones initially set?

Both this API and Subnet-EVM relies on Validation ID rather than NodeID. The case where different Validation IDs mapped to same NodeID should already be handled by the state (here), so this API should not return duplicated ones.

For the Subnet-EVM we first handle deletions when we handle the new set from P-Chain. It guarantees that we delete the uptime from the state, even if the same nodeID is being deleted + readded under different validationIDs in the same load period. After deletion we add new data with the same nodeID. See here

@ceyonur ceyonur mentioned this pull request Nov 9, 2024
uint64 weight = 2;
bytes public_key = 3;
uint64 start_time = 4;
uint64 set_weight_nonce = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is set_weight_nonce for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's the MinNonce of L1 validators

IsSov: vdr.IsSoV,
}
if vdr.PublicKey != nil {
// This is a performance optimization to avoid the cost of compression
Copy link
Contributor

@yacovm yacovm Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serializing in compressed form is cheap. It is the de-compression that is expensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

literally copied from L73

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

Though I think that this comment is a bit misleading - what it's probably actually trying to say is that in order to avoid the expensive decompression in the client side, the server side is not compressing.

@@ -831,6 +833,64 @@ func (s *state) DeleteExpiry(entry ExpiryEntry) {
s.expiryDiff.DeleteExpiry(entry)
}

func (s *state) GetCurrentValidatorSet(ctx context.Context, subnetID ids.ID) (map[ids.ID]*validators.GetCurrentValidatorOutput, uint64, error) {
result := make(map[ids.ID]*validators.GetCurrentValidatorOutput)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to check currentStakers is not nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentStakers are initialized to be empty in New

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants